package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class IODemo9 {
    public static void main(String[] args) {
        //使用OutPutStream来写文件
        try(OutputStream outputStream = new FileOutputStream("./test.txt")) {
            String s = "你好中国";
            byte[] buffer = s.getBytes("utf-8");
            outputStream.write(buffer);
            // 不要忘记 flush
            outputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    public static void main2(String[] args) {
        //使用OutPutStream来写文件
        try(OutputStream outputStream = new FileOutputStream("./test.txt")) {
            String s = "Nothing";
            byte[] buffer = s.getBytes();
            outputStream.write(buffer);
            // 不要忘记 flush
            outputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main1(String[] args) {
        //使用OutPutStream来写文件
        try(OutputStream outputStream = new FileOutputStream("./test.txt")) {
            byte[] buffer = new byte[]{97,98,99,100,101,102};
            outputStream.write(buffer);
            // 不要忘记 flush
            outputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } ;
    }
}
